package grame;

public class Coordinates 
{
	protected int x;
	protected int y;
	public Coordinates(Coordinates c)
	{
		this.x=c.getX();
		this.y=c.getY();
	}
	public Coordinates(int x, int y)
	{
		this.x=x;
		this.y=y;
	}
	public Coordinates(Base b)
	{
		int row=b.getRows();
		int col=b.getColumns();
		this.x=(int)(Math.random()*col);
		this.y=(int)(Math.random()*row);
	}
	public Coordinates()
	{
		this.x=0;
		this.y=0;
	}
	public int getX()
	{
		return this.x;
	}
	public int getY()
	{
		return this.y;
	}
	void setXY(int num1, int num2)
	{
		this.x+=num1;
		this.y+=num2;
	}
	public boolean equals(Coordinates c)
	{
		if((this.getX()==c.getX())&&(this.getY()==c.getY()))
			return true;
		return false;
	}
	public String toString()
	{
		String st="("+this.x+", "+this.y+")";
		return st;
	}
	public Coordinates addDir(Dir d)
	{
		int newX=this.x+d.getX();
		int newY=this.y+d.getY();
		return new Coordinates(newX, newY);
	}
	public int distance(Coordinates c)
	{
		return Math.abs((int)(Math.sqrt((Math.pow(c.getX()-this.getX(), 2))+Math.pow(c.getY()-this.getY(), 2))));
	}
	public Coordinates[] getSurrounding()
	{
		Coordinates[] sur=new Coordinates[8];
		sur[0]=this.addDir(new Dir("up"));
		sur[1]=this.addDir(new Dir(1, -1));
		sur[2]=this.addDir(new Dir("right"));
		sur[3]=this.addDir(new Dir(1, 1));
		sur[4]=this.addDir(new Dir("down"));
		sur[5]=this.addDir(new Dir(-1, 1));
		sur[6]=this.addDir(new Dir("left"));
		sur[7]=this.addDir(new Dir(-1, -1));
		return sur;
	}
}